﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

public class IncubatorObject:ViewableObject
{
    protected new Type thisType;
    protected bool creatingDone = false;
    protected Animation creating;
    protected bool isCreating = false;

    public IncubatorObject(IncubatorObject.Type type, Vector3 placement)
        : base(type, placement)
    {
        thisType = type;
        creating = new Animation(thisType.createName, thisType.createFramerate, thisType.createLoopable, thisType.createFrames);
    }

    public Vector3 createPlacement(CollidableObject co)
    {
        return origin - new Vector3(0, 0, co.myType.collisionBoxDimentions.Z+1);
    }

    public void startCreating()
    {
        if (!isCreating)
        {
            currentAnimation = creating;
            isCreating = true;
            Game.getGame().getSoundManager().playOneSoundEffect(((AudioAsset)Game.getGame().getAssetLibrary().getAudio(AssetLibrary.audioType.SOUND_EFFECT).get("prof_regen")).sound, 1.0f);
        }
    }

    public bool isCreatingDone()
    {
        if (creatingDone)
        {
            creatingDone = false;
            isCreating = false;
            return true;
        }
        else
        {
            return creatingDone;
        }
    }

    public override void update(double elapsed)
    {
        //dont call base.update b/c i dont want to be culled
        currentAnimation.update(elapsed);
        screenCoord = Camera.worldToScreen(origin);

        if (creating.isFinished)
        {
            creatingDone = true;
            currentAnimation = stasis;
            creating.setCurrentFrame(0);
            creating.isFinished = false;
        }
    }

    public new class Type : ViewableObject.Type
    {
        public static readonly Type Incubator = new Type(
            ObjectFactory.TypeEnum.Incubator,//type
            new Vector3(182, 665, 0),//origin
            new Vector3(365, 665, 365),//collision
            false,//walkable
            new ArrayList { /*
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronStaticSpriteSheet"),//1095x665 
                    new Rectangle(0, 0, 365, 665), 
                    0, 
                    new Vector2(182, 665)),
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronStaticSpriteSheet"),//1095x665 
                    new Rectangle(365, 0, 365, 665), 
                    0, 
                    new Vector2(182, 665)),*/
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronStaticSpriteSheet"),//1095x665 
                    new Rectangle(730, 0, 365, 665), 
                    0, 
                    new Vector2(182, 665))/*,
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronStaticSpriteSheet"),//1095x665 
                    new Rectangle(365, 0, 365, 665), 
                    0, 
                    new Vector2(182, 665))*/},//frameList
            "incubatorStasis",//animation name
            6,//framerate
            true,//loopable
            new ArrayList { 
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronChargingSpriteSheet"), 
                    new Rectangle(0, 0, 365, 665), 
                    0, 
                    new Vector2(182, 665)),
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronChargingSpriteSheet"), 
                    new Rectangle(365, 0, 365, 665), 
                    0, 
                    new Vector2(182, 665)),
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronChargingSpriteSheet"), 
                    new Rectangle(730, 0, 365, 665), 
                    0, 
                    new Vector2(182, 665)),
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronChargingSpriteSheet"), 
                    new Rectangle(1095, 0, 365, 665), 
                    0, 
                    new Vector2(182, 665)),
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronChargingSpriteSheet"), 
                    new Rectangle(1460, 0, 365, 665), 
                    0, 
                    new Vector2(182, 665)),
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronChargingSpriteSheet"), 
                    new Rectangle(0, 665, 365, 665), 
                    0, 
                    new Vector2(182, 665)),
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronChargingSpriteSheet"), 
                    new Rectangle(365, 665, 365, 665), 
                    0, 
                    new Vector2(182, 665)),
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronChargingSpriteSheet"), 
                    new Rectangle(730, 665, 365, 665), 
                    0, 
                    new Vector2(182, 665)),
                new Frame(
                    Game.getGame().getAssetLibrary().get(AssetLibrary.assetType.STATIC_WORLD_OBJECTS).get("regentronChargingSpriteSheet"), 
                    new Rectangle(1095, 665, 365, 665), 
                    0, 
                    new Vector2(182, 665))},//frameList
            "incubatorCreate",//animation name
            6,//framerate
            false);//loopable

        public ArrayList createFrames
        {
            get { return create_frames; }
        }
        protected ArrayList create_frames;

        public String createName
        {
            get { return create_name; }
        }
        protected String create_name;

        public int createFramerate
        {
            get { return create_framerate; }
        }
        protected int create_framerate;

        public bool createLoopable
        {
            get { return create_loopable; }
        }
        protected bool create_loopable;

        protected Type(ObjectFactory.TypeEnum type, Vector3 origin, Vector3 collision, Boolean walkable,
            ArrayList stasisFrames, String stasisName, int stasisFramerate, Boolean stasisLoopable, 
            ArrayList createFrames, String createName, int createFramerate, Boolean createLoopable)
            : base(type, origin, collision, walkable, stasisFrames, stasisName, stasisFramerate, stasisLoopable)
        {
            create_frames = createFrames;
            create_name = createName;
            create_framerate = createFramerate;
            create_loopable = createLoopable;
        }

        public new static IncubatorObject.Type getType(ObjectFactory.TypeEnum te)
        {
            switch (te)
            {
                case ObjectFactory.TypeEnum.Incubator: return Incubator;
            }
            return null;
        }
    }
}
